package com.lc.recovery.ui.activity.recoverymine;

import android.os.Bundle;
import android.util.Log;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.recovery.R;
import com.lc.recovery.app.AppActivity;
import com.lc.recovery.http.request.WorkerStockShowApi;
import com.lc.recovery.http.response.WorkerStockShowBean;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class AlreadyWarehousingDetailsActivity extends AppActivity {
    @BindView(R.id.rv_keruku)
    RecyclerView rvKeruku;
    private List<WorkerStockShowBean.DataBean> dataBeanList = new ArrayList<>();
    private BaseQuickAdapter<WorkerStockShowBean.DataBean, BaseViewHolder> alreadywarehousingsadapter;
    private String shop_id;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_alreadywarehousingdetails;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);

        shop_id = getIntent().getStringExtra("id");
        workerStockShow();
        Log.e("TAG", "onCreate: "+ shop_id);
        alreadywarehousingsadapter = new BaseQuickAdapter<WorkerStockShowBean.DataBean, BaseViewHolder>(R.layout.item_alreadywarehousingdetails, dataBeanList) {
            @Override
            protected void convert(@NotNull BaseViewHolder baseViewHolder, WorkerStockShowBean.DataBean bean) {
                baseViewHolder.setText(R.id.tv_type, bean.getShops());
                baseViewHolder.setText(R.id.tv_date, bean.getCreate_time());
                baseViewHolder.setText(R.id.tv_weight, bean.getWeights()+"kg");
                baseViewHolder.setText(R.id.tv_difference, bean.getDifference_weights()+"kg");
                baseViewHolder.setText(R.id.tv_chae, "差额款：￥"+bean.getDifference_money());
                baseViewHolder.setText(R.id.tv_shifu, "实付款：￥"+bean.getAmount());
            }
        };
        rvKeruku.setAdapter(alreadywarehousingsadapter);
    }

    private void workerStockShow() {

            EasyHttp.post(this)
                    .api(new WorkerStockShowApi().setId(shop_id)).request(new HttpCallback<WorkerStockShowBean>(this) {

                @Override
                public void onSucceed(WorkerStockShowBean data) {
                    if (data.getCode() == 200) {
                        dataBeanList.clear();
                        dataBeanList.add(data.getData());

                        alreadywarehousingsadapter.setNewData(dataBeanList);
                        alreadywarehousingsadapter.notifyDataSetChanged();


                    } else {
                        toast(data.getMsg());
                    }
                }


                @Override
                public void onFail(Exception e) {
//                    super.onFail(e);

                }
            });
        }

}
